package com.cxy.msclass.controller;


import com.cxy.msclass.domain.entity.Lesson;
import com.cxy.msclass.service.LessonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/lessons")
public class LessonController {
    @Autowired
    private LessonService lessonService;

    /**
     * 购买指定id的课程
     * @param id
     */
    @GetMapping("/buy/{id}")
    public Lesson buyById(@PathVariable Integer id){
        //1.根据id查询lesson
        //2. 根据lesson.id查询user_lesson,那么直接返回，如果没有
        //3.如果user_lesson==null &&用户余额>lesson.price，就购买
        return this.lessonService.buyById(id);

    }
}
